package com.itxiaoxiong.chat.controller;

import com.itxiaoxiong.chat.socket.ProxyServer;
import com.itxiaoxiong.chat.pojo.Result;
import com.itxiaoxiong.chat.pojo.User;
import com.itxiaoxiong.chat.service.LoginService;
import com.itxiaoxiong.chat.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class LoginController {

    @Autowired
    private LoginService loginService;

    /*
    登录操作
     */
    @PostMapping("/login")
    public Result login(@RequestBody User user){
        log.info("登录: {}", user);
        User u = loginService.login(user);
        return u != null?Result.success(u):Result.error("用户名或密码错误");
    }

    /*
    退出操作
     */
    @GetMapping("/outLogin")
    public Result outLogin(@RequestParam Integer id){
        log.info("根据id进行退出登录的操作:{}", id);
        loginService.outLogin(id);

        return Result.success();
    }

}
